package com.lhd._05mvcboot03.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author lhd
 * @date 2024/4/26
 * @apiNote
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    Integer state;
    String message;
    Object data;

    //没有相应数据
    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    //有相应数据
    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    //成功操作 带返回数据的
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    //成功操作 不带返回数据的
    public static JsonResult ok() {
        return ok(null);
    }
}
